.<template>
  <div class="border-1">
    <div class="footcart">
      <div class="cartbox">
        <div class="cartleft" @click="foldFn">
          <div class="iconbox">
            <i class="log" :class="{ active: totalCount > 0 }">
              <svg
                t="1622809211226"
                class="icon"
                viewBox="0 0 1024 1024"
                version="1.1"
                xmlns="http://www.w3.org/2000/svg"
                p-id="3167"
                width="24"
                height="24"
                @click="show = !show"
              >
                <path
                  d="M334.476 778.285c-49.041 0-88.318 39.72-88.318 88.761s39.278 88.762 88.318 88.762 88.761-39.72 88.761-88.762c0.001-49.04-39.72-88.761-88.761-88.761zM68.19 68.19v88.762h88.762l159.55 336.629-59.915 108.733c-6.879 12.87-10.874 27.295-10.874 42.827 0 49.041 39.72 88.762 88.762 88.762h532.57v-88.762H353.338c-6.213 0-11.095-4.882-11.095-11.095 0-1.998 0.444-3.772 1.331-5.326l39.72-72.34h330.638c33.286 0 62.355-18.419 77.667-45.712l158.662-288.032c3.55-6.214 5.547-13.537 5.547-21.304 0-24.63-19.972-44.38-44.38-44.38H255.256L213.094 68.19H68.191z m710.094 710.094c-49.041 0-88.318 39.72-88.318 88.761s39.278 88.762 88.318 88.762 88.761-39.72 88.761-88.762c0-49.04-39.72-88.761-88.761-88.761z"
                  p-id="3168"
                  fill="#ffffff"
                ></path>
              </svg>
            </i>
          </div>
          <div class="totalPrice" :class="{ active: totalPrice > 0 }">
            <span>¥{{ totalPrice }}</span>
          </div>
          <div class="deliveryPrice">
            <span>另需配送费¥{{ evaluate.deliveryPrice }}元</span>
          </div>
          <div class="cartright">
            <span>{{ rightText }}</span>
          </div>
        </div>
      </div>
      <div class="list" v-show="show">
        <div class="list-header">
          <span class="header-cart">购物车</span>
          <span class="header-clear" @click="clearbtn">清空</span>
          <span></span>
        </div>
        <div class="list-content">
          <ul>
            <li
              class="list-item"
              v-for="(item, index) in shopcart"
              :key="index"
            >
              <span class="list-item-left">{{ item.name }}</span>
              <div class="list-item-right">
                <div class="price">
                  <span>$10</span>
                </div>
                <div class="list-item-icon">
                  <div class="delbtn">
                    <svg
                    @click="addbtn(item,1)"
                      t="1622535874477"
                      class="icon"
                      viewBox="0 0 1024 1024"
                      version="1.1"
                      xmlns="http://www.w3.org/2000/svg"
                      p-id="5746"
                      width="26"
                      height="26"
                    >
                      <path
                        d="M512 928c-229.4 0-416-186.6-416-416S282.6 96 512 96s416 186.6 416 416-186.6 416-416 416z m0-768c-194 0-352 158-352 352s158 352 352 352 352-158 352-352S706 160 512 160z"
                        p-id="5747"
                        fill="#1296db"
                      ></path>
                      <path
                        d="M672 544H352c-17.6 0-32-14.4-32-32s14.4-32 32-32h320c17.6 0 32 14.4 32 32s-14.4 32-32 32z"
                        p-id="5748"
                        fill="#1296db"
                      ></path>
                    </svg>
                  </div>
                  <span>{{item.count}}</span>
                  <div class="addbtn">
                    <svg
                    @click="addbtn(item,0)"
                      t="1622535643005"
                      class="icon"
                      viewBox="0 0 1024 1024"
                      version="1.1"
                      xmlns="http://www.w3.org/2000/svg"
                      p-id="5266"
                      width="26"
                      height="26"
                    >
                      <path
                        d="M512 928c-229.4 0-416-186.6-416-416S282.6 96 512 96s416 186.6 416 416-186.6 416-416 416z m0-768c-194 0-352 158-352 352s158 352 352 352 352-158 352-352S706 160 512 160z"
                        p-id="5267"
                        fill="#1296db"
                      ></path>
                      <path
                        d="M512 704c-17.6 0-32-14.4-32-32v-128h-128c-17.6 0-32-14.4-32-32s14.4-32 32-32h128v-128c0-17.6 14.4-32 32-32s32 14.4 32 32v128h128c17.6 0 32 14.4 32 32s-14.4 32-32 32h-128v128c0 17.6-14.4 32-32 32z"
                        p-id="5268"
                        fill="#1296db"
                      ></path>
                    </svg>
                  </div>
                </div>
              </div>
            </li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState, mapGetters } from "vuex";
//  import PubSub from 'pubsub-js'
import BScroll from "better-scroll";
export default {
  name: "foot",
  data() {
    return {
      show: true,
    };
  },
  props: {
    selectedFoods: Array,
  },
  computed: {
    ...mapState(["evaluate"]),
    ...mapGetters(["shopcart"]),
    //总价钱
    totalPrice() {
      return this.selectedFoods.reduce((adder, selectedFood) => {
        return adder + selectedFood.count * selectedFood.price;
      }, 0);
    },
    //结算文案
    rightText() {
      if (this.totalPrice === 0) {
        return `¥${this.evaluate.minPrice}元起送`;
      } else if (this.totalPrice < this.evaluate.minPrice) {
        return `还差¥${this.evaluate.minPrice - this.totalPrice}元起送`;
      } else if (this.totalPrice >= this.evaluate.minPrice) {
        return `去结算`;
      }
    },
    // 总数量
    totalCount() {
      return this.selectedFoods.reduce((adder, selectedFood) => {
        return adder + selectedFood.count;
      }, 0);
    },
    //购物车列表的折叠
  },
  methods: {
    clearbtn() {
      console.log(1111)
      this.$store.commit("clearbtn");
    },
        addbtn(food,v){
      this.$store.commit("getshop",{food,v})
      console.log(1111)
    },
    foldFn() {
      //看门狗  当总数量小于等于0的时候 我们点击购物车的左侧时
      // 不应该让fold产生任何改变
      if (this.totalCount <= 0) {
        return;
      }
      this.fold = !this.fold;
    },
  },
};
</script>

<style lang="less" scopend>
// .border-1{
//   height: 100%;
//       background-color: rgba(7, 17, 27, 0.8);
//     backdrop-filter: blur(10px);
  
// }
.footcart {
  position: fixed;
  flex: 0 0 0;
  z-index: 3;
  bottom: 0;
  left: 0;
  height: 100px;
  width: 100%;
  display: flex;
  background-color: #141d27;

  .cartbox {
    .cartleft {
      flex: 1;
      height: 100%;
      display: flex;
      .iconbox {
        position: relative;
        bottom: 25px;
        width: 120px;
        height: 120px;
        border-radius: 50%;
        background-color: #141d27;
        margin-left: 12px;
        margin-right: 12px;
        display: flex;
        justify-content: center;
        align-items: center;
        .log {
          display: flex;
          justify-content: center;
          align-items: center;
          width: 90px;
          height: 90px;
          border-radius: 50%;
          background-color: rgba(255, 255, 255, 0.4);
          &.active {
            background-color: rgb(0, 160, 220);
          }
        }
      }
      .totalPrice {
        display: flex;
        justify-content: center;
        align-items: center;
        margin-right: 12px;
        font-size: 26px;
        line-height: 24px;
        font-weight: 700;
        color: rgba(255, 255, 255, 0.4);
        span {
          font-size: 0.5rem;
          font-weight: 700;
          color: rgba(255, 255, 255, 0.4);
        }
        &.active {
          color: white;
        }
      }
      .deliveryPrice {
        display: flex;
        justify-content: center;
        align-items: center;
        span {
          font-size: 28px;
          width: 240px;
          line-height: 48px;
          font-weight: 700;
          color: rgba(255, 255, 255, 0.4);
          padding-left: 12px;
          border-left: 2px solid rgba(255, 255, 255, 0.1);
        }
      }
      .cartright {
        flex: 0 0 210px;
        height: 100%;
        background-color: rgba(255, 255, 255, 0.4);
        display: flex;
        justify-content: center;
        align-items: center;
        width: 210px;
        margin-left: 78px;
      }
    }
  }
  .list {
    position: fixed;
    z-index: 10;
    left: 0;
    bottom: 130px;
    width: 100%;
    padding-bottom: 20px;
    background-color: white;
      //  height: 996px;
    
    .list-header {
      one-px: (rgba(7, 17, 27, 0.1));
      // height: 40px;
      background-color: #f3f5f7;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .header-cart {
        padding-left: 36px;
        color: rgb(7, 17, 27);
        font-weight: 800;
        font-size: 28px;
      }
      .header-clear {
        margin-right: -6.52rem;
        color: rgba(0, 160, 220, 1);
        font-size: 28px;
        font-weight: 800;
      }
    }
    .list-content {
      // max-height: 611px;
      // overflow: hidden;
      ul {
        // height: 96px;
        .list-item {
          one-px: (rgba(7, 17, 28, 0.1));
          display: flex;
          height: 96px;
          align-items: center;
          justify-content: space-between;
          padding-top: 12px;
          padding-bottom: 24px;
          .list-item-left {
            font-size: 28px;
            color: rgb(7, 17, 27);
            line-height: 48px;
            padding-left: 30px;
          }
          .list-item-right {
            display: flex;
            align-items: center;
            .price {
              padding-right: 24px;
              span {
              }
            }
            .list-item-icon {
              display: flex;
              align-items: center;
              .delbtn {
                padding-right: 24px;
              }
              .addbtn {
                padding-left: 24px;
              }
            }
          }
        }
      }
    }
  }
}
</style>